<?php
include 'secure/core.php';
if(isset($_POST['submit'])){
        if (!isset($_POST['agreement'])) {
		header( 'Location: register.php?msg=1' ) ;	
		exit;
	}
	$result = $users->registerUser($_POST);
	
	if($result == 1){
		header( 'Location: login.php?msg=2' ) ;					
		exit;
	}
	else{
		header( 'Location: register.php?msg=2' ) ;	
		exit;
	}		

}
include 'header.php';
include 'left.php'; 
?>
		<div id="right">

			<div class="section">
                        <?php if($_GET['msg'] == '1') { ?>
			 <div class="message red"><span><b>Error</b>: You must accept the Terms of Service.</span></div>
			 <?php } ?>
			 <?php if($_GET['msg'] == '2') { ?>
			 <div class="message red"><span><b>Error</b>: The Username or Email already exists.</span></div>
			 <?php } ?>
							<div class="box">

					<div class="title">

						Register

					</div>

					<div class="content">

						<form action="register.php" method="post">

							<div class="row">

								<label>Username</label>

								<div class="right"><input type="text" value="" name="username" class="{validate:{required:true, messages:{required:'Please enter your username'}}}" /></div>

							</div>

							<div class="row">

								<label>Street Address</label>

								<div class="right"><input type="text" value="" name="address" class="{validate:{required:true, messages:{required:'Please enter your address'}}}" /></div>

							</div>

							<div class="row">

								<label>Full Name</label>

								<div class="right"><input type="text" value="" name="name" class="{validate:{required:true, messages:{required:'Please enter your real name'}}}" /></div>

							</div>

							<div class="row">

								<label>Contact Number</label>

								<div class="right"><input type="text" value="" name="contact_number" class="{validate:{required:true, messages:{required:'Please enter your contact number'}}}" /></div>

							</div>

							<div class="row">

								<label>Country</label>

								<div class="right">
                                                                <?php echo $users->getCountrySelectBox($row['country_iso']);?>
								</div>

							</div>

							<div class="row">

								<label>Email</label>

								<div class="right"><input type="text" value="" name="email" class="{validate:{required:true, email:true, messages:{required:'Please enter your email address'}}}" /></div>

							</div>

							<div class="row">

								<label>Password</label>

								<div class="right"><input type="password" value="" name="password" class="{validate:{required:true, messages:{required:'Please enter your password'}}}" /></div>

							</div>
						
							<?php if(isset($_GET['ref'])){?>
							<div class="row">
							
							        <label>Referral</label>
							        
							        <div class="ref">
							        
							        <div class="right"><input type="text" value="<?php echo $_GET['ref']; ?>" name="referral" disabled="" /></div>
							        
							        </div>
							        
							 </div>
							 <?php } ?>     
							 
							 
							<div class="row">

								<label>Agreement</label>

								<div class="right">

									<input type="checkbox" name="agreement" id="agreement"/>

									<label for="agreement">I have read and accept the <a href="tos.php" >Terms of Service</a></label>

								</div>

							</div>

							<div class="row">

								<div class="right">

									<button name="submit" id="submit" type="submit" class="green"><span>Submit</span></button>

								</div>

							</div>

						</form>

					</div>

				</div>

			</div>

		</div>

<?php include 'footer.php'; ?>